#!/usr/bin/perl
=pod
vim:ts=4
=cut

# parameters to sweep
@nums = (50);
@times = (30,60,120,240);

# executable name of the baseline program
$base = "fish-moving-grid";

# executable names of the comparison programs
@execs = ("fish-moving-grid-omp");

# number of trials to average
$trials = 10;

# auto print endlines
$\ = "\n";

# capture CTRL-C
$SIG{INT} = sub { exit(0); };

# file output
open FILE, ">", "test.txt" or die $!;

foreach $n(@nums) {
	foreach $t(@times) {
		# multiplying the time by 100 is a reasonable estimate for the steps
		$s = 100 * $t;
		# get the base time for the serial version
		$time = 0;
		for ($i = 0; $i < $trials; $i++) {
			$_ = `./$base -n $n -t $t -s $s -u`;
			print($base);
			print($_);
			if (/Total time taken: ([\d\.]+)/) {
				$time += $1;
			}
		}
		$basetime = $time / $trials;
		if ($basetime == 0) {
			die("Error: could not establish base time.");
		}
		# run the parallel versions and output the speedup
		foreach $e(@execs) {
			$time = 0;
			for ($i = 0; $i < $trials; $i++) {
				$_ = `./$e -n $n -t $t -s $s -u`;
				print($e);
				print($_);
				if (/Total time taken: ([\d\.]*)/) {
					$time += $1;
				}
			}
			$time /= $trials;
			$speedup = $basetime / $time;
			print FILE "$e\t$n\t$t\t$speedup";
		}
	}
}
